package com.my.study.finaltest;

import java.sql.Connection;
import java.util.Random;

/**
 * @author Carlos
 * @version 1.0
 * @Description TODO
 * @date 2021/6/5 11:34
 **/
public class PoolTest {

    public static void main(String[] args) {
        PoolFlyweight pool = new PoolFlyweight(2);

        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                Connection conn = pool.borrow();
                try {
                    Thread.sleep(new Random().nextInt(1000));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                pool.free(conn);
            }, String.valueOf(i + 1)).start();
        }
    }
}
